package cn.xu.bookstore.cart.domain;

import java.math.BigDecimal;

import cn.xu.bookstore.book.domain.Book;

/*
 * 购物车条目
 * 购物车条目：商品+数量
 */
public class CartItem {
	private Book book;//商品
	private Integer count;//数量
	
	
	/*
	 * 提供一个计算小计的方法
	 * 处理误差的现象
	 */
	public Double getSubtotal(){
		BigDecimal price = new BigDecimal(book.getPrice());
		BigDecimal _count = new BigDecimal(count);
		return _count.multiply(price).doubleValue();
	}
	
	
	public CartItem() {
		super();
		// TODO Auto-generated constructor stub
	}
	public CartItem(Book book, Integer count) {
		super();
		this.book = book;
		this.count = count;
	}
	public Book getBook() {
		return book;
	}
	public void setBook(Book book) {
		this.book = book;
	}
	public Integer getCount() {
		return count;
	}
	public void setCount(Integer count) {
		this.count = count;
	}
	@Override
	public String toString() {
		return "CartItem [book=" + book + ", count=" + count + "]";
	}
	
	
}
